package clasesGraficas;

import org.achartengine.model.CategorySeries;
import org.achartengine.renderer.DefaultRenderer;
import org.achartengine.renderer.SimpleSeriesRenderer;
import android.graphics.Color;

public class VentasN3 {
	public CategorySeries series = null;
	public DefaultRenderer render = null;
	private int[] valores = null;
	
	public void ejecutar(int [] valores){
		this.valores = valores;
		int suma = sumarValores(this.valores);
		series = new CategorySeries("Ventas");
		int k = 0;
		for (int value:valores){
			series.add("Evento " + ++k + ": " + Math.round(((double)(value)/(double)(suma))*100) + "%",value);
		}
		
		int[] colores = new int [] {Color.BLUE, Color.GREEN,
				Color.DKGRAY,Color.RED};

		render = new DefaultRenderer();
		for (int color:colores){
			SimpleSeriesRenderer r = new SimpleSeriesRenderer();
			r.setColor(color);
			r.setChartValuesSpacing(5);
			r.setChartValuesTextSize(25);
			render.addSeriesRenderer(r);
		}
		
		render.setChartTitle("Ventas por subtipo de evento");
		render.setFitLegend(true);
		render.setChartTitleTextSize(30);
		render.setLabelsColor(Color.BLACK); //Esto es para todos los labels
		render.setMargins(new int[] {150, 150, 170, 100}); //{arriba, derecha, izquierda, abajo}
		render.setLegendTextSize(25);
		render.setLegendHeight(70);
		render.setZoomRate(1.1f);
		render.setZoomButtonsVisible(true);
	}
	
	public int sumarValores(int[] valores){
		int valor = 0;
		
		for (int i=0;i<valores.length;i++)
			valor += valores[i];
		return valor;
	}
}
